<div class="modal-header">
    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
    <h4 class="modal-title">阈值管理</h4>
</div>
<form id="defaultForm" method="post" class="form-horizontal" action="/project/indexManage/threshold_save">
    <div class="modal-body">
        <input name="id" style="display: none" th:value="${thresholdInfo.id}">
        <div class="form-group">
            <label class="col-lg-3 control-label">编号</label>
            <div class="col-lg-6">
                <input type="text" class="form-control" name="code" th:value="${thresholdInfo.code}"/>
            </div>
        </div>

        <div class="form-group">
            <label class="col-lg-3 control-label">名称</label>
            <div class="col-lg-6">
                <input type="text" class="form-control" name="name" th:value="${thresholdInfo.name}"/>
            </div>
        </div>


        <div class="form-group">
            <label class="col-lg-3 control-label">适用对象</label>
            <div class="col-lg-6">
                <select class="form-control" name="objName">
                    <option th:each="parameter:${objects}" th:value="${parameter.id}" th:text="${parameter.name}"
                            th:selected="${parameter.id eq thresholdInfo.objName + ''}"></option>
                </select>
            </div>
        </div>

        <div class="form-group">
            <label class="col-lg-3 control-label">来源</label>
            <div class="col-lg-6">
                <input name="sources" type="hidden" th:value=${thresholdInfo.source}>
                <b>计算:</b><input type="checkbox" name="source" value="1" onclick="aaa()"/>
                </br>
                <b>诊断:</b><input type="checkbox" name="source" value="2" onclick="aaa()"/>
                </br>
                <b>通信:</b><input type="checkbox" name="source" value="3" onclick="aaa()"/>
            </div>

        </div>

        <div class="form-group">
            <label class="col-lg-3 control-label">是否可修改</label>
            <div class="col-lg-6">
                <div class="checkbox">
                    <label>
                        <input type="checkbox" name="isModify" th:value="${thresholdInfo.isModify}"
                               th:checked="${thresholdInfo.isModify}" value="0"
                               onclick="this.value=(this.value==0)?1:0">
                    </label>
                </div>
            </div>
        </div>

        <div class="form-group">
            <label class="col-lg-3 control-label">系统默认值</label>
            <div class="col-lg-6">
                <input type="text" class="form-control" name="sysDefVal" th:value="${thresholdInfo.sysDefVal}"/>
            </div>
        </div>

        <div class="form-group">
            <label class="col-lg-3 control-label">单位</label>
            <div class="col-lg-6">
                <input type="text" class="form-control" name="unit" th:value="${thresholdInfo.unit}"/>
            </div>
        </div>


    </div>
    <div class="modal-footer">
        <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
        <button type="submit" class="btn btn-primary">保存</button>
    </div>
</form>

<script>
    //    //表单初始化
    initCheck();

    function aaa() {
        var str = "";
        $("input[name='source']:checked").each(function (i) {
            if (i == 0) {
                str = $(this).val();
            } else {
                str += "," + $(this).val();
            }
            console.log(str);
        })
    }

    $("input[name='sources']").each(function () {
        var bbb = $(this).val();
        console.log(bbb);
        if (bbb == '1') {
            $("input[value='1']").prop("checked", true);
        }
        if (bbb == '2') {
            $("input[value='2']").prop("checked", true);
        }
        if (bbb == '3') {
            $("input[value='3']").prop("checked", true);
        }
        if (bbb == '1,2,3') {
            $("input[name='source']").prop("checked", true);
        }
        if (bbb == '1,2') {
            $("input[value='1']").prop("checked", true);
            $("input[value='2']").prop("checked", true);
        }
        if (bbb == '1,3') {
            $("input[value='1']").prop("checked", true);
            $("input[value='3']").prop("checked", true);
        }
        if (bbb == '2,3') {
            $("input[value='2']").prop("checked", true);
            $("input[value='3']").prop("checked", true);
        }

    })
</script>